let assert = require('assert');
let exec = require('child_process').exec;
let fs = require('fs-extra');
let utils = require('./utils');

describe('diagrams dot', function(){
    it('should create .svg from .dot files', function(cb) {
        let generatedSVGPath = `${utils.getTmpDir()}/dot.svg`;
        exec(`./bin/diagrams.js dot tests/fixtures/dot/simple.dot ${generatedSVGPath}`, (err) => {
            if(err){
                return cb(err);
            }

            fs.readFile(generatedSVGPath, (err, fileContent) => {
                if(err){
                    return cb(err);
                }
                
                assert.equal(
                    fileContent.toString(),
`<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
 "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
<!-- Generated by graphviz version 2.40.1 (20161225.0304)
 -->
<!-- Title: G Pages: 1 -->
<svg width="316pt" height="260pt"
 viewBox="0.00 0.00 316.26 260.00" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink">
<g id="graph0" class="graph" transform="scale(1 1) rotate(0) translate(4 256)">
<title>G</title>
<polygon fill="#ffffff" stroke="transparent" points="-4,4 -4,-256 312.2641,-256 312.2641,4 -4,4"/>
<!-- main -->
<g id="node1" class="node">
<title>main</title>
<ellipse fill="none" stroke="#000000" cx="162.7737" cy="-234" rx="30.1958" ry="18"/>
<text text-anchor="middle" x="162.7737" y="-229.8" font-family="Times,serif" font-size="14.00" fill="#000000">main</text>
</g>
<!-- parse -->
<g id="node2" class="node">
<title>parse</title>
<ellipse fill="none" stroke="#000000" cx="117.7737" cy="-162" rx="31.3179" ry="18"/>
<text text-anchor="middle" x="117.7737" y="-157.8" font-family="Times,serif" font-size="14.00" fill="#000000">parse</text>
</g>
<!-- main&#45;&gt;parse -->
<g id="edge1" class="edge">
<title>main&#45;&gt;parse</title>
<path fill="none" stroke="#000000" d="M152.1093,-216.937C146.6968,-208.277 140.0069,-197.5731 133.9741,-187.9207"/>
<polygon fill="#000000" stroke="#000000" points="136.9421,-186.0657 128.6741,-179.4407 131.0061,-189.7757 136.9421,-186.0657"/>
</g>
<!-- init -->
<g id="node4" class="node">
<title>init</title>
<ellipse fill="none" stroke="#000000" cx="58.7737" cy="-90" rx="27" ry="18"/>
<text text-anchor="middle" x="58.7737" y="-85.8" font-family="Times,serif" font-size="14.00" fill="#000000">init</text>
</g>
<!-- main&#45;&gt;init -->
<g id="edge3" class="edge">
<title>main&#45;&gt;init</title>
<path fill="none" stroke="#000000" d="M136.8398,-224.0956C117.5726,-215.3876 92.2221,-200.83 77.7737,-180 65.2375,-161.9268 60.6909,-137.2489 59.1656,-118.305"/>
<polygon fill="#000000" stroke="#000000" points="62.6519,-117.9629 58.5881,-108.1784 55.6632,-118.3614 62.6519,-117.9629"/>
</g>
<!-- cleanup -->
<g id="node5" class="node">
<title>cleanup</title>
<ellipse fill="none" stroke="#000000" cx="207.7737" cy="-162" rx="41.1316" ry="18"/>
<text text-anchor="middle" x="207.7737" y="-157.8" font-family="Times,serif" font-size="14.00" fill="#000000">cleanup</text>
</g>
<!-- main&#45;&gt;cleanup -->
<g id="edge4" class="edge">
<title>main&#45;&gt;cleanup</title>
<path fill="none" stroke="#000000" d="M173.4381,-216.937C178.8506,-208.277 185.5405,-197.5731 191.5732,-187.9207"/>
<polygon fill="#000000" stroke="#000000" points="194.5412,-189.7757 196.8733,-179.4407 188.6052,-186.0657 194.5412,-189.7757"/>
</g>
<!-- printf -->
<g id="node7" class="node">
<title>printf</title>
<ellipse fill="none" stroke="#000000" cx="275.7737" cy="-18" rx="32.4808" ry="18"/>
<text text-anchor="middle" x="275.7737" y="-13.8" font-family="Times,serif" font-size="14.00" fill="#000000">printf</text>
</g>
<!-- main&#45;&gt;printf -->
<g id="edge8" class="edge">
<title>main&#45;&gt;printf</title>
<path fill="none" stroke="#000000" d="M190.0989,-226.117C212.1982,-218.2219 242.1241,-203.7675 257.7737,-180 284.3841,-139.586 283.4766,-80.8842 279.9399,-46.3558"/>
<polygon fill="#000000" stroke="#000000" points="283.3721,-45.5726 278.7307,-36.0486 276.4198,-46.3883 283.3721,-45.5726"/>
</g>
<!-- execute -->
<g id="node3" class="node">
<title>execute</title>
<ellipse fill="none" stroke="#000000" cx="162.7737" cy="-90" rx="40.548" ry="18"/>
<text text-anchor="middle" x="162.7737" y="-85.8" font-family="Times,serif" font-size="14.00" fill="#000000">execute</text>
</g>
<!-- parse&#45;&gt;execute -->
<g id="edge2" class="edge">
<title>parse&#45;&gt;execute</title>
<path fill="none" stroke="#000000" d="M128.4381,-144.937C133.8506,-136.277 140.5405,-125.5731 146.5732,-115.9207"/>
<polygon fill="#000000" stroke="#000000" points="149.5412,-117.7757 151.8733,-107.4407 143.6052,-114.0657 149.5412,-117.7757"/>
</g>
<!-- make_string -->
<g id="node6" class="node">
<title>make_string</title>
<ellipse fill="none" stroke="#000000" cx="58.7737" cy="-18" rx="58.5482" ry="18"/>
<text text-anchor="middle" x="58.7737" y="-13.8" font-family="Times,serif" font-size="14.00" fill="#000000">make_string</text>
</g>
<!-- execute&#45;&gt;make_string -->
<g id="edge5" class="edge">
<title>execute&#45;&gt;make_string</title>
<path fill="none" stroke="#000000" d="M140.718,-74.7307C126.3296,-64.7695 107.3013,-51.596 91.2029,-40.451"/>
<polygon fill="#000000" stroke="#000000" points="92.8231,-37.3158 82.6089,-34.5013 88.8386,-43.0711 92.8231,-37.3158"/>
</g>
<!-- execute&#45;&gt;printf -->
<g id="edge6" class="edge">
<title>execute&#45;&gt;printf</title>
<path fill="none" stroke="#000000" d="M186.1874,-75.0816C203.4876,-64.0584 227.1779,-48.9637 245.8517,-37.0653"/>
<polygon fill="#000000" stroke="#000000" points="247.7484,-40.007 254.3011,-31.6816 243.9868,-34.1035 247.7484,-40.007"/>
</g>
<!-- compare -->
<g id="node8" class="node">
<title>compare</title>
<ellipse fill="none" stroke="#000000" cx="179.7737" cy="-18" rx="44.0622" ry="18"/>
<text text-anchor="middle" x="179.7737" y="-13.8" font-family="Times,serif" font-size="14.00" fill="#000000">compare</text>
</g>
<!-- execute&#45;&gt;compare -->
<g id="edge9" class="edge">
<title>execute&#45;&gt;compare</title>
<path fill="none" stroke="#000000" d="M167.0635,-71.8314C168.8817,-64.131 171.0436,-54.9743 173.0642,-46.4166"/>
<polygon fill="#000000" stroke="#000000" points="176.5344,-46.95 175.4261,-36.4133 169.7218,-45.3414 176.5344,-46.95"/>
</g>
<!-- init&#45;&gt;make_string -->
<g id="edge7" class="edge">
<title>init&#45;&gt;make_string</title>
<path fill="none" stroke="#000000" d="M58.7737,-71.8314C58.7737,-64.131 58.7737,-54.9743 58.7737,-46.4166"/>
<polygon fill="#000000" stroke="#000000" points="62.2738,-46.4132 58.7737,-36.4133 55.2738,-46.4133 62.2738,-46.4132"/>
</g>
</g>
</svg>
`
                )
                cb(null);
            });
        })
    });
});
